using System.Collections.Generic;
using UnityEngine;

namespace CinemaDirector
{
	[CutsceneItem("GameObject", "Visibility")]
	public class GGVisibilityAction : GGTweenPropertyBase<bool>
	{
		public class CachedGO
		{
			public bool value;

			public GameObject theObject;
		}

		public List<GameObject> otherObjects = new List<GameObject>();

		protected List<CachedGO> otherCached = new List<CachedGO>();

		public override void SetProperty(bool newPropertyValue)
		{
			if (obj.activeSelf != newPropertyValue)
			{
				obj.SetActive(newPropertyValue);
			}
			foreach (GameObject otherObject in otherObjects)
			{
				if (otherObject.activeSelf != newPropertyValue)
				{
					otherObject.SetActive(newPropertyValue);
				}
			}
		}

		public override bool GetProperty()
		{
			return obj.activeSelf;
		}

		public override void Initialize()
		{
			base.Initialize();
			if (Application.isPlaying)
			{
				return;
			}
			otherCached.Clear();
			foreach (GameObject otherObject in otherObjects)
			{
				otherCached.Add(new CachedGO
				{
					value = otherObject.activeSelf,
					theObject = otherObject
				});
			}
		}

		public override void Stop()
		{
			base.Stop();
			if (Application.isPlaying)
			{
				return;
			}
			SetProperty(cachedProperty);
			foreach (CachedGO item in otherCached)
			{
				item.theObject.SetActive(item.value);
			}
		}
	}
}
